package com.yz.test.okhttp.service;

import com.yz.test.okhttp.mapper.UserMapper;
import com.yz.test.okhttp.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class UserService {


    @Autowired
    UserMapper userMapper;

    public User login(String username,String password){
        User byUsername = userMapper.findByUsername(username);
        if (byUsername==null) return new User();
        if (byUsername.getPassword().equalsIgnoreCase(password)){
            return byUsername;
        }
        return new User();
    }

    public List<User> findAll(){
        List<User> all = userMapper.findAll();
        return all.stream().filter(e->e.getUsername()!=null).collect(Collectors.toList());
    }
}
